<template>
  <el-select v-model="year" placeholder="请选择年份" @change="onChange">
    <el-option
      v-for="item in years"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
</template>

<script>

  const year = new Date().getFullYear();

  export default {
    components:{  },
    name: 'YearSelect',
    data(){
      return {
        years:[],
        year:year
      }
    },
    props:{
      value:{
        type:Number,
        required:false
      },
    },
    watch:{
      value(val){
        this.year = val;
      }
    },
    created(){
      for(var i = 2016;i<= year+1;i++){
        this.years.push({
          value:i,
          label:i
        });
      }
      this.$nextTick(function () {
        this.$emit("input",year);
        this.$emit("change",year);
      })
    },
    mounted(){

    },
    methods:{
      onChange(val){
        this.$emit("input",val);
        this.$emit("change",val);
      }
    }
  }
</script>

<style scoped>
  el-input{
    cursor:pointer;
  }
</style>
